---
title: Establish claim context and load a claim
summary: Bind a claim manager to a claim by claim number, claim id, or worker id and load the claim's data.
status: draft
owner: SAIF Documentation Generator
last_reviewed: 2026-08-21
library: SAIF.Application.Claim
reference_type: embedded
operation_id: OP-CLM-1
trigger: A UI screen or derived manager binds to a claim via SetClaimContext/SetWorkerContext.
---

# Establish claim context and load a claim

This operation is the entry point every claim-oriented manager uses to bind to a claim: it validates the supplied key, replaces the immutable context object, and runs the fixed retrieve/security/screen-data pipeline.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-CLM-1 |
| **Trigger** | A UI screen or derived manager calls `SetClaimContext` or `SetWorkerContext` |
| **Inputs** | Claim number, claim id, or worker id |
| **Outputs** | Populated `ClaimData`, an access classification, and a user `Message` |
| **Primary components** | `ClaimAppManager.SetClaimContext`, `ClaimAppManager.SetWorkerContext`, `ClaimAppManager.ChangeContext` |
| **Entry point** | `SAIF.Application.Claim/ClaimAppManager.vb` |

## Steps

1. Validate the supplied key: a claim number must be non-blank after trim; a claim id or worker id must be greater than zero ([BR-CLM-001](../business-rules.md#br-clm-001-claim-context-key-validation)).
   - On failure: clear `m_ClaimData`, call `MarkContextNotSet()`, set `Message = ClaimAppConstants.PLEASEENTERCLAIM`, and return without any retrieval. `SetWorkerContext` returns silently on an invalid worker id without setting a message.
2. Replace the context object: construct a new `ClaimContext` (by claim number, claim id, or worker id), which sets `ContextSet = True` ([BR-CLM-002](../business-rules.md#br-clm-002-claim-context-immutability)).
3. `ChangeContext()` runs the fixed pipeline: `OnContextChanged()` → `OnCheckSecurity()` → `OnRetrieve()` ([BR-CLM-003](../business-rules.md#br-clm-003-fixed-context-change-pipeline-order)).
4. `OnContextChanged()` calls `GetClaimData()`: when `Context.ContextSet`, retrieve the claim by claim id if `ClaimID > 0`, otherwise by claim number; then `MarkContextSet()`.
   - Delegated logic: retrieval of the claim row is implemented in `clsClaimData.GetData(DPI, key)` (`SAIF.BOF.Business.View.Claim`); SQL and tables were not traced in this pass.**
   > **Origin**: The claim row retrieval is implemented in `SAIF.BOF.Business.View.Claim` (`clsClaimData`) and executed on behalf of this operation; its SQL was not traced in this analysis pass.
5. Evaluate the retrieval outcome: set `Message = ClaimAppConstants.CLAIMNOTFOUND` and `MarkContextNotSet()`; then, if `m_ClaimData.IsValid`, clear the message and `MarkContextSet()` ([BR-CLM-004](../business-rules.md#br-clm-004-context-validity-requires-a-valid-retrieved-claim)).
   - If the context is worker-only (`WorkerID` set, `ClaimID = 0`, blank claim number): step 4 runs with an empty claim number, so `ClaimData` is not expected to be valid.*
6. `OnCheckSecurity()` runs — see [Evaluate claim access](evaluate-claim-access.md).
7. `OnRetrieve()` — abstract in this library; the derived manager loads its screen-specific data. Not traced here.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start([Set*Context called]) --> Valid{Key valid?}
	Valid -->|No| Blocked(["Message: enter valid claim<br>number, no retrieval"])
	Valid -->|Yes| NewCtx[Construct new ClaimContext]
	NewCtx --> Pipeline["ChangeContext:<br>OnContextChanged"]
	Pipeline --> LoadClaim["GetClaimData via<br>clsClaimData"]
	LoadClaim --> Found{ClaimData.IsValid?}
	Found -->|No| NotFound(["Message: claim not found,<br>MarkContextNotSet"])
	Found -->|Yes| SetOk[MarkContextSet]
	SetOk --> CheckSec[OnCheckSecurity]
	CheckSec --> OnRetrieve["OnRetrieve: derived screen<br>load"]
```

## Failure and edge-case behavior

- An invalid key short-circuits at step 1; no exception is thrown for a missing claim.
- If `ClaimData` is `Nothing` (context never set), `OnCheckSecurity` will dereference it — reachability in production is unknown.**

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Security and authorization](../security-authorization.md)

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- `SAIF.Application.Claim/ClaimAppManager.vb`
- `SAIF.Application.Claim/ClaimContext.vb`
- `SAIF.Application.Claim/ClaimAppConstants.vb`
